#!/bin/bash
fmt="+%Y%m%d"
if [ $# -lt 1 ]; then
  cat << EOF 
  Usage: $0 ndates date  [fmt]
  default format is $fmt  
  format should be YYYYMMDD or any other acceptable format for date command 
  full precision down to seconds (if specified will be computed) but only 
  up to date will be printed by default 
  default is to add 
  if a third argument is present, it is treated as the format specifier 
  for output. e.g.  '+%Y%m%d%H%M%S' to get full precision 
  (Assela Pathirana, 2006)  
EOF
  exit 1
fi
dates=$1
if [ $# -ge 2 ]; then
  thisdate=`date --date "$2" +'%s'`
else
  date=''
  thisdate=`date +'%s'`
fi
newdate=`echo $thisdate $dates|awk '{printf "%20i", $1+$2*24*3600}'`
if [ $# -ge 3 ]; then
  fmt=$3
fi

date  --date=" 1970-01-01 00:00:00 UTC $newdate  seconds"  "$fmt"

